
var origin1=main_detect(url);
var origin_ip=ndv;



console.log("phase 7 complete");

console.log("网关设备",origin1);
console.log("链接在网关的其他路由器和交换机信息",origin_ip);




var m=[];

var a=origin1.info;
var b=origin_ip["网络设备下的设备信息"][0];

for(var i=0;i<b["mac"].length;i++){
    var mac=b["mac"][i];
    var mtmp=mac.split(":");
    var mac1="";
    for(var p=0;p<mtmp.length;p++){
        var tmp_p=mtmp[p];
        if(mtmp[p].length==1){
            tmp_p="0"+tmp_p;
        }

        if(p==(mtmp.length-1)){
            mac1=mac1+tmp_p;
        }else{
            mac1=mac1+tmp_p+":";
        }
    }

    var ip1=b["ip_address"][i];

    for(var j=0;j<a["mac"].length;j++){
        var mac2=a["mac"][j];
        var port1=a["port"][j];

        if(mac1==mac2){

            m[m.length]={"mac":mac2,"ip":ip1,"port":port1};

        }
    }

}


console.log("数据:",m);

console.log("交换机,无线ap,路由器",sr);

$(".go_snmp").removeClass("hidden");

var source_data=[];

source_data[0]={ip:url,port:"0",name:dv1["sysName"],type:dv1["sysType"]};


for(var i=0;i< m.length;i++){

    var ip=m[i]["ip"];
    //router info
    for(var j=0;j<routers.length;j++){
        if(ip==routers[j]["ip"]){


            console.log(ip," 对应的端口号",m[i]["port"],"sysName",routers[j]["sysName"]);
            var text=ip+" 对应的端口号:"+m[i]["port"]+" sysName:"+routers[j]["sysName"];


            var tmp="<div class=\"col-xs-12  progress \" style=\"height:30px;\">"+
                text
                +"</div>";

            source_data[source_data.length]={ip:ip,port:m[i]["port"],name:routers[j]["sysName"],type:routers[j]["sysType"]};


            $(".main").append(tmp);



        }
    }

    //switch info
    for(var k=0;k<switchs.length;k++){
        if(ip==switchs[k]["ip"]){

            console.log(ip,"对应的端口号",m[i]["port"],"sysName",switchs[k]["sysName"]);

            var text=ip+" 对应的端口号:"+m[i]["port"]+" sysName:"+switchs[k]["sysName"];


            var tmp="<div class=\"col-xs-12  progress \" style=\"height:30px;\">"+
                text
                +"</div>";


            source_data[source_data.length]={ip:ip,port:m[i]["port"],name:switchs[k]["sysName"],type:switchs[k]["sysType"]};

            $(".main").append(tmp);


        }
    }



    //airport info
    for(var l=0;l<airports.length;l++){
        if(ip==airports[l]["ip"]){


            console.log(ip," 对应的端口号",m[i]["port"],"sysName",airports[l]["sysName"]);
            var text=ip+" 对应的端口号:"+m[i]["port"]+" sysName:"+airports[l]["sysName"];


            var tmp="<div class=\"col-xs-12  progress \" style=\"height:30px;\">"+
                text
                +"</div>";



            source_data[source_data.length]={ip:ip,port:m[i]["port"],name:airports[l]["sysName"],type:airports[l]["sysType"]};


            $(".main").append(tmp);

        }
    }


    //others info
    for(var n=0;n<others.length;n++){
        if(ip==others[n]["ip"]){


            console.log(ip," 对应的端口号",m[i]["port"],"sysName",others[n]["sysName"]);
            var text=ip+" 对应的端口号:"+m[i]["port"]+" sysName:"+others[n]["sysName"];


            var tmp="<div class=\"col-xs-12  progress \" style=\"height:30px;\">"+
                text
                +"</div>";


            source_data[source_data.length]={ip:ip,port:m[i]["port"],name:others[n]["sysName"],type:others[n]["sysType"]};



            $(".main").append(tmp);

        }
    }






}






console.log("final data:",source_data);

var data={"nodes":[],"edges":[]};
var nodes=[];
var edges=[];


nodes[0]={"id":source_data[0]["port"],"label":source_data[0]["ip"]+"  "+source_data[0]["name"]+" "+source_data[0]["type"],"tooltip":source_data[0]["name"],"x":800,"y":10};





edges[0]={"source":source_data[0]["port"],"target":source_data[0]["port"],"label":source_data[0]["ip"],"tooltip":source_data[0]["ip"]};






for(var i=1;i<source_data.length;i++){



    nodes[nodes.length]={"id":source_data[i]["port"],"label":source_data[i]["ip"]+"  "+source_data[i]["name"]+" "+source_data[i]["type"],"tooltip":source_data[i]["name"],"x":250,"y":50+50*i};


    edges[edges.length]={"source":source_data[0]["port"],"target":source_data[i]["port"],"label":source_data[i]["ip"],"tooltip":source_data[i]["ip"]};





}


data["nodes"]=nodes;
data["edges"]=edges;




if(source_data.length>0){
    $.ajax({
        url:"op.php",
        type:"post",
        data:{data:JSON.stringify(data)},
        dataType:"json",
        success:function(e){

            if(e.success){

                window.open("lib/image/image.html");


            }
        }

    });
}
